package org.example.mynote.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.example.mynote.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.example.mynote.Entity.Note;

import java.util.List;

@RestController
@RequestMapping("/api/favorites")
@Tag(name = "收藏相关接口")
@Slf4j
@SecurityRequirement(name = "BearerAuth")
public class FavoriteController {
    @Autowired
    private FavoriteService favoriteService;


    /**
     * 收藏一篇笔记
     * URL: POST /api/favorites/{noteId}
     */
    @PostMapping("/{noteId}")
    @Operation(summary = "收藏一篇指定的笔记")
    public ResponseEntity<Void> addFavorite(@PathVariable Long noteId) {
        favoriteService.addFavorite(noteId);
        return ResponseEntity.ok().build();
    }

    /**
     * 取消收藏一篇笔记
     * URL: DELETE /api/favorites/{noteId}
     */
    @DeleteMapping("/{noteId}")
    @Operation(summary = "取消收藏一篇指定的笔记")
    public ResponseEntity<Void> removeFavorite(@PathVariable Long noteId) {
        favoriteService.removeFavorite(noteId);
        return ResponseEntity.noContent().build();
    }

    /**
     * 获取当前用户的所有收藏笔记
     * URL: GET /api/favorites
     */
    @GetMapping
    @Operation(summary = "获取我收藏的所有笔记列表")
    public ResponseEntity<List<Note>> getMyFavorites() {
        List<Note> favoriteNotes = favoriteService.getMyFavorites();
        return ResponseEntity.ok(favoriteNotes);
    }
}
